<?php
/**
 * Created by PhpStorm.
 * User: 1
 * Date: 2016-10-17
 * Time: 12:00
 */

namespace app\src\extend\sms;
use app\src\message\config\MessageConfig;
use app\src\message\facade\MessageEntity;
use app\src\message\sms\QCloudSms;


/**
 * 短信统一调用接口
 * Class SmsFacade
 * @package app\src\extend\sms
 */
class SmsFacade
{

    /**
     * 发送
     * @param MessageEntity $msg
     * @return array
     */
    public function send(MessageEntity $msg){

        //获取配置 来调用相应的短信服务
        $ret = [];

        switch (MessageConfig::getMsgType()){
            case MessageConfig::TYPE_LOCAL:
                $ret = ['status'=>true,'info'=>lang('tip_message_your_code_is',['code'=>$msg->getCode()])];
                break;
            case MessageConfig::TYPE_QCLOUD:
                //腾讯短信内容
                //TODO: 更通用处理【香岛纺织】
                $content = "【香岛纺织】{1}为您的验证码，请于{2}分钟内填写。如非本人操作，请忽略本短信。";
                $content = str_replace("{1}",$msg->getCode(),$content);
                $content = str_replace("{2}","10",$content);
                $msg->setContent($content);
                $ret = (new QCloudSms(MessageConfig::getExtraCfg()))->init($msg)->send();
                
                break;
            default:
                break;
        }

        return $ret;
    }

}